package github.kawaiior.yuanchuxiuzhen.core.init.event;

import github.kawaiior.yuanchuxiuzhen.core.init.BlockInit;
import github.kawaiior.yuanchuxiuzhen.util.BiomeUtil;
import net.minecraft.block.BlockState;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraft.world.gen.placement.TopSolidRangeConfig;
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
import net.minecraftforge.event.world.BiomeLoadingEvent;

public class OreGenerationEvent {

    private static void initOres(BiomeGenerationSettingsBuilder generation, BlockState state, int maxSize,
                                 int weight, int bottomOffset, int topOffset, int maximum){
        generation.withFeature(GenerationStage.Decoration.UNDERGROUND_DECORATION, Feature.ORE.withConfiguration(
                new OreFeatureConfig(OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, state, maxSize))
                .withPlacement(Placement.RANGE.configure(new TopSolidRangeConfig(bottomOffset,topOffset,maximum)))
                .square().chance(weight));
    }

    private static void generateManaStone(final BiomeLoadingEvent event){
        if (!BiomeUtil.isMainWorldBiome(event.getCategory())){
            return;
        }
        BiomeGenerationSettingsBuilder generation = event.getGeneration();

        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_1.get().getDefaultState(),
                24, 1, 4, 12, 72);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_2.get().getDefaultState(),
                22, 2, 4, 10, 68);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_3.get().getDefaultState(),
                20, 2, 4, 8, 60);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_4.get().getDefaultState(),
                18, 3, 4, 8, 56);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_5.get().getDefaultState(),
                16, 3, 4, 8, 48);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_6.get().getDefaultState(),
                14, 4, 4, 6, 40);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_7.get().getDefaultState(),
                12, 4, 2, 4, 36);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_8.get().getDefaultState(),
                10, 5, 2, 4, 32);
        initOres(generation, BlockInit.MANA_STONE_ORE_BLOCK_9.get().getDefaultState(),
                8, 5, 2, 4, 30);
    }

    public static void generateOres(final BiomeLoadingEvent event){
        generateManaStone(event);

//        if(! (event.getCategory().equals(Biome.Category.NETHER) || event.getCategory().equals(Biome.Category.THEEND))){
//            BiomeGenerationSettingsBuilder generation = event.getGeneration();
//            generation.withFeature(GenerationStage.Decoration.UNDERGROUND_DECORATION,
//                    Feature.ORE.withConfiguration(
//                            new OreFeatureConfig(
//                                    OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
//                                    BlockInit.EXAMPLE_BLOCK.get().getDefaultState(),
//                                    5)).withPlacement(Placement.RANGE.configure(new TopSolidRangeConfig(15,0,64)))
//                            .square().func_242731_b(20));
//        }

    }
}
